package ce.com.cenewbluesdk.entity.k3;

import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import ce.com.cenewbluesdk.uitl.ByteParser;
import ce.com.cenewbluesdk.uitl.TimeUtil;

/**
 * Created by Administrator on 2016/11/21.
 */
public class Sport_Info_Struct_K3 implements Parcelable  {
    protected Sport_Info_Struct_K3(Parcel in) {
        type = in.readByte();
        time = in.readLong();
        steps = in.readInt();
        distance = in.readInt();
        calories = in.readInt();
        reserved = in.readInt();
        duration = in.readInt();
    }

    public static final Creator<Sport_Info_Struct_K3> CREATOR = new Creator<Sport_Info_Struct_K3>() {
        @Override
        public Sport_Info_Struct_K3 createFromParcel(Parcel in) {
            return new Sport_Info_Struct_K3(in);
        }

        @Override
        public Sport_Info_Struct_K3[] newArray(int size) {
            return new Sport_Info_Struct_K3[size];
        }
    };

    public static int getItemSize() {
        return 16;
    }

    /**
     * 运动类型
     */
    public static final byte SPORT_TYPE_NULL = 0;
    public static final byte SPORT_TYPE_STEP = 1;
    public static final byte SPORT_TYPE_RUN = 2;
    public static final byte SPORT_TYPE_WEIGHT = 3;
    public static final byte SPORT_TYPE_BIKE = 4;
    public static final byte SPORT_TYPE_LIFT = 5;
    public static final byte SPORT_TYPE_SUM = 6;

    // 运动类型
    private byte type = SPORT_TYPE_STEP;
    // 运动开始时间
    private long time;
    private int steps;
    private int distance;
    private int calories;
    @Deprecated
    private int reserved;

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    private int duration;

    public Sport_Info_Struct_K3(byte type, long time, int steps, int distance, int calories, int reserved) {
        this.type = type;
        this.time = time;
        this.steps = steps;
        this.distance = distance;
        this.calories = calories;
        this.reserved = reserved;
    }

    public Sport_Info_Struct_K3(byte[] sportBytes) {
        ByteParser parser = new ByteParser(sportBytes);
        duration = parser.readInt(2);
        time = TimeUtil.s2CForDev(parser.readInt(4), true).getTimeInMillis();
        steps = parser.readInt(4);
        distance = parser.readInt(4);
        calories = parser.readInt(2);
    }

    public static Sport_Info_Struct_K3 parseSportInfo(byte[] sportBytes) {
        Log.d("rd65", Arrays.toString(sportBytes));
        return new Sport_Info_Struct_K3(sportBytes);
//
//        int offset = 0;
//
//        byte type = sportBytes[offset];
//        offset++;
//
//        byte[] minsTo1970 = new byte[4];
//        System.arraycopy(sportBytes, offset, minsTo1970, 0, 4);
////        int tMinsTo1970 = Data_Block_Head_T.byteToInt2(minsTo1970);
////        long tlMinsTo1970 = (long) tMinsTo1970 * 1000;
//        Calendar c = TimeUtil.byte2C(minsTo1970, true);
//        offset += 4;
//
//        byte[] tSteps = new byte[4];
//        System.arraycopy(sportBytes, offset, tSteps, 0, 4);
//        int tmpSteps = Data_Block_Head_T.byteToInt2(tSteps);
//
//        offset += 4;
//        byte[] tDistance = new byte[4];
//        System.arraycopy(sportBytes, offset, tDistance, 0, 4);
//        int tmpDistance = Data_Block_Head_T.byteToInt2(tDistance);
//
//        offset += 4;
//        byte[] tCalories = new byte[2];
//        System.arraycopy(sportBytes, offset, tCalories, 0, 2);
//        int tmpCalories = byteToShort2(tCalories)/* * 100*/;
//
//        offset++;
//        int reserved = sportBytes[offset];
//
//        return new Sport_Info_Struct_K3(type, c.getTimeInMillis(), tmpSteps, tmpDistance, tmpCalories, reserved);
    }

    @Override
    public String toString() {
        return "Sport_Info_Struct_K3{" +
                "type=" + type +
                ", time=" + time +
                ", steps=" + steps +
                ", distance=" + distance +
                ", calories=" + calories +
                ", reserved=" + reserved +
                ", duration=" + duration +
                ", timeStr=" + TimeUtil.long2String(time) +
                '}';
    }

    public byte getType() {
        return type;
    }

    public void setType(byte type) {
        this.type = type;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public int getSteps() {
        return steps;
    }

    public void setSteps(int steps) {
        this.steps = steps;
    }

    public int getDistance() {
        return distance;
    }

    public void setDistance(int distance) {
        this.distance = distance;
    }

    public int getCalories() {
        return calories;
    }

    public void setCalories(int calories) {
        this.calories = calories;
    }

    public int getReserved() {
        return reserved;
    }

    public void setReserved(int reserved) {
        this.reserved = reserved;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByte(type);
        dest.writeLong(time);
        dest.writeInt(steps);
        dest.writeInt(distance);
        dest.writeInt(calories);
        dest.writeInt(reserved);
        dest.writeInt(duration);
    }
}
